package org.example.repository;

import java.util.HashMap;
import java.util.Map;

public class SchemaManager {

    private final SchemaSynchronizer schemaSynchronizer;
    private final Map<String, Schema> schemas = new HashMap<>();

    public SchemaManager(SchemaSynchronizer schemaSynchronizer) {
        this.schemaSynchronizer = schemaSynchronizer;
    }

    /**
     * add schema, usually read from config file or annotations
     */
    public void put(Schema schema) {
        this.schemas.put(schema.name(), schema);
    }

    /**
     * get schema by name
     */
    public Schema get(String name) {
        return this.schemas.get(name);
    }

    /**
     * sync schema to database
     */
    public void sync() {
        for (Schema schema : schemas.values()) {
            schemaSynchronizer.sync(schema);
        }
    }
}
